/**
 * @author Jamada
 */
public class FingerTable {

    /**
     * Finger table data.
     */
    private final Node[] fingerNodes;

    /**
     * Node references for this local node.
     */
    private final NodeReferences references;
    
    /**
     * The local node ID.
     */
    private final int localID;
    
    /**
     * 
     * 
     * @param localID The local node ID.
     * @param references NodeReferences object.
     */
    public FingerTable(final int localID, final NodeReferences references) {
        this.localID = localID;
        this.references = references;
        this.fingerNodes = new Node[references.getMValue()];
    }
    
    /**
     * Sets a given index of the finger table to the given reference.
     * 
     * @param index Index of table entry.
     * @param nodeReference Reference to store.
     */
    public final void setFinger(int index, Node nodeReference) {
    	fingerNodes[index] = nodeReference;
    }
    
    /**
     * Returns the reference stored at the given index.
     * 
     * @param index Index of finger to be returned.
     * @return Reference stored at the given index.
     */
    public final Node getFinger(int index) {
        return fingerNodes[index];
    }
    
    /**
     * Adds the given reference to all finger table entries of which the start
     * index is in the interval (local node ID, new node ID) and of which the
     * current entry is null or further away from the local node
     * ID than the new node ID (ie. the new node ID is in the interval (local
     * node ID, currently stored node ID)).
     * 
     * @param nodeReference Reference to be added to the finger table.
     */
    public final void addReference(Node nodeReference) {
        //check for null pointer
    }
    
    /**
     * Determines closest preceding node of given id.
     * 
     * @param key ID of which the closest preceding node shall be determined.
     * @return Reference to the node which most closely precedes the given ID.
     *         null if no node has been found.
     */
    public final Node getClosestPrecedingNode(final int key) {
        Node result = null;
        
        return result;
    }
    
    /**
     * Removes all occurences of the given node from finger table.
     * 
     * @param node Reference to be removed from the finger table.
     */
    public final void removeReference(Node node) {
        //check for null pointer
    }
    
    /**
     * Determines if the given reference is stored somewhere in the finger
     * table.
     * 
     * @param newReference Reference being checked.
     * @return true, if the given reference exists in the finger
     *         table, or else false.
     */
    public final boolean containsReference(Node newReference) {
        //check for null pointer
        boolean result = false;
        
        return result;
    }
    
    
    /**
     * Local node id.
     */
}
